# 2024/1/10 17:51 HFL

import pymysql

from common.configmysql import configmysql


def selectpymysqql(sql):
    # 连接数据库-生成游标-执行SQL--关闭游标-关闭链接
    with pymysql.connect(
        host=configmysql().get('host'),
        user=configmysql().get('user'),
        password=configmysql().get('password'),
        port=int(configmysql().get('port')),
        database=configmysql().get('database'),
    ) as conn:
        ccs = conn.cursor()
        ccs.execute(sql)
        # 查看结果的第一行
        data = ccs.fetchone()
        # 关闭游标数据库连接
        return data


if __name__ == '__main__':
    sql = 'select * from book limit 1'
    print(selectpymysqql(sql))
